package com.wltjack.springboot.controller.jms;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;
import javax.jms.Queue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/jms/queue")
public class QueueController {
	private transient final Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private JmsMessagingTemplate jmsMessagingTemplate;
	
	@Resource(name = "testQueue")
	private Queue testQueue;
	
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	// http://127.0.0.1:8080/learn/jms/queue/sendTestMsg
	@RequestMapping("/sendTestMsg")
	public void sendMsgToQueue() {
		String msg = "新发送的测试消息！time=" + sdf.format(new Date());
		log.info("to Queue[name='active.test.queue'] send msg: "+msg);
		// 指定消息发送的目的地及内容
		this.jmsMessagingTemplate.convertAndSend(this.testQueue, msg);

	}
	
	
}
